﻿using System;
using System.Collections.Generic;

using NUnit.Framework;

using VidoopSecure;
using VidoopSecureExtensionMethods;

namespace TestVidoopSecure
{
    [TestFixture]
    public class TestVoiceOtpService : BaseTest
    {
        [TestFixtureSetUp]
        public override void SetUp()
        {
            base.SetUp();
        }

        [TestFixtureTearDown]
        public override void TearDown()
        {
            base.TearDown();
        }
        
        [Test]
        public void Test_GetService()
        {
            Service voiceOtpService = Manager.GetService(
                "voiceotp", CurrentSite);
            Assert.IsNotNull(voiceOtpService);
        }

        [Test]
        public void Test_NewVoiceOtp()
        {
            VoiceOtpService service = (VoiceOtpService)Manager.GetService(
                "voiceotp", CurrentSite);
            Assert.IsNotNull(service);

            Random rand = new Random(DateTime.Now.Millisecond);
            string userId = RandomString(8,false);
            string phone = Settings.PhoneNumber;
            VoiceOtp voiceotp = service.NewVoiceOtp(userId, phone);
            Assert.IsNotNull(voiceotp);

            Assert.AreEqual(phone, voiceotp.Phone);
            Assert.AreEqual("pending", voiceotp.SendStatus);
            Assert.AreEqual("pending", voiceotp.AuthenticationStatus);

            // In order for the rest to work, you have to answer the phone call
            // that contains the OTP in the message.
            //
            // Test the GET of the transaction status
            //VoiceOtp voiceotp2 = service.GetVoiceOtp(voiceotp.Id);
            //Assert.IsNotNull(voiceotp2);

            //Assert.AreEqual(phone, voiceotp2.Phone);
            //Assert.IsTrue("pending" == voiceotp2.SendStatus ||
            //              "success" == voiceotp2.SendStatus);
            //Assert.AreEqual("pending", voiceotp2.AuthenticationStatus);
       }


        // In order to test this, you need a current VoiceOtp AND its code.
        // Since an VoiceOtp containing the code is sent in an audio message
        // to a phone, we don't have plumbing to get it and use the code here.
        // Instead, this testing has to be done manually.
        //
        //[Test]
        //public void Test_ValidateVoiceOtp()
        //{
        //    VoiceOtpService service = (VoiceOtpService)Manager.GetService(
        //        "voiceotp", CurrentSite);
        //    Assert.IsNotNull(service);

        //    VoiceOtp voiceOtp = service.GetVoiceOtp("7");
        //    Assert.IsNotNull(voiceOtp);

        //    string code = "831458";
        //    Assert.IsTrue(service.ValidateVoiceOtp(voiceOtp.Id, code));
        //}
    }
}
